<?php

/**
 * @author Kien Tran <kien.tran@logigear.com>
 */
class ContactController extends AdminController {

    const MODEL_CLASS_NAME = 'Contact';

    public function actionIndex() {

	$url = $_SERVER['REQUEST_URI'];
	$model = new Contact("search");
	$model->unsetAttributes();  // clear any default values
	
	if (isset($_GET[self::MODEL_CLASS_NAME])) {
	    $model->attributes = $_GET[self::MODEL_CLASS_NAME];
	    Yii::app()->user->setState(app()->controller->id . self::MODEL_CLASS_NAME, $_GET[self::MODEL_CLASS_NAME]);
	} else {
	    $articleState = Yii::app()->user->getState(app()->controller->id . self::MODEL_CLASS_NAME);
	    if ($articleState != null)
		$model->attributes = $articleState;
	}

	$this->render('index', array(
	    'model' => $model,
	));
    }

    public function actionRefresh() {
	Yii::app()->user->setState(app()->controller->id . self::MODEL_CLASS_NAME, null);
	$this->redirect(url(app()->controller->id . "/index"));
    }

    function actions() {
	return array(
	    'delete' => array(
		'class' => 'lib.components.actions.DeleteAction',
		'ajaxView' => "//share/_delete",
		'messages' => array('success' => t('MSG_INFO_DELETE_SUCCESS', 'messages', array('{0}' => 'Contact')))
	    ),
	);
    }

    public function loadModel() {
	$model = null;
	if (isset($_GET['id'])) {
	    $ids = explode(',', $_GET['id']);
	    if (isset($ids)) {
		$criteria = new CDbCriteria;
		$criteria->addInCondition('id', $ids);
		$model = Contact::model()->findAll($criteria);
	    }
	}
	return $model;
    }

}

